package com.feibi.study.Basic

import android.app.ActivityManager
import android.app.ActivityManager.RunningAppProcessInfo
import android.app.Application
import android.content.Context

class BasicApplication : Application() {
    override fun onCreate() {
        super.onCreate()

    }

    /**
     * 應用是否處於後台
     */
    fun isBackground(): Boolean {
        val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        val appProcesses = activityManager.runningAppProcesses
        var isBackground = true
        for (appProcess in appProcesses) {
            if (appProcess.processName == packageName) {
                isBackground =
                    !(appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND || appProcess.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE)
            }
        }
        return isBackground
    }


}